<%-- 
    Document   : download_submission
    Created on : 2011年8月27日, 上午09:58:44
    Author     : Terry
--%>

<%@page import="unilearn.vo.Role"%>
<%@page import="unilearn.vo.Person"%>
<%@page import="unilearn.bo.AccessValidator"%>
<%@page import="unilearn.bo.SubjectManagement"%>
<%@page import="unilearn.vo.Submission"%>
<%@page import="unilearn.vo.Assignment"%>
<%@page import="unilearn.bo.AssignmentManagement"%>
<%@page import="unilearn.dao.AssignmentDAO"%>
<%@page import="unilearn.vo.Subject"%>
<%@page import="java.util.List"%>
<%@page import="unilearn.dao.SubjectDAO"%>
<%@page import="unilearn.bo.SubmissionManagement"%>
<%@page import="org.springframework.web.context.support.WebApplicationContextUtils"%>
<%@page import="org.springframework.web.context.WebApplicationContext"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
        <%            
            WebApplicationContext context = WebApplicationContextUtils.getRequiredWebApplicationContext(this.getServletContext());
            SubmissionManagement submMgt = (SubmissionManagement) context.getBean("submMgt");
            AccessValidator vaildater = (AccessValidator) context.getBean("accessValidator");
            SubjectManagement subjectMgt = (SubjectManagement) context.getBean("subjectMgt");
            AssignmentManagement assignMgt = (AssignmentManagement) context.getBean("assignMgt");

            HttpSession s = request.getSession();

            Person person = (Person) s.getAttribute("person");
            Role role = (Role) s.getAttribute("role");
            
            List<Subject> subs = null;
            if (role.getName().equals("student")) {
                subs = subjectMgt.getStudentSubjects(person);
            } else if (role.getName().equals("staff")) {
            } else if (role.getName().equals("lecturer")) {
                subs = subjectMgt.getConvernorSubjects(person);
                subs.addAll(subjectMgt.getMarkerSubjects(person));
            } else if (role.getName().equals("administrator")) {
            }
                        
            if (subs == null) {
                return;
            }
            if (role.getName().equals("student") || role.getName().equals("lecturer")){   
                out.print(" <option value=\"\">Select Your Assignment</option>");
                for (Subject sub : subs) {
                    List<Assignment> assigns = assignMgt.getAssignments(sub);
                    if (assigns == null) {
                        break;
                    }     

                    if (sub.getSubjectCode().equals((String)request.getParameter("subject")) ){                    
                        for (Assignment assign : assigns) {                             
                            out.print("<option  value=\""+ assign.getId() +"\" > Assignment " + assign.getId() +"</option>");                
                        }
                    }                                                                                   
                }
            }
        %>
